/**
 * 闭包实现单例模式
 * @return {function}
 */
function genGetInstance() {
  let instance; // 闭包
  class Singleton {}
  return () => {
    if (instance == null) {
      instance = new Singleton();
    }
    return instance;
  };
}

const getInstance = genGetInstance();
const g1 = getInstance();
const g2 = getInstance();
console.log(g1 === g2); // true
